package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class DtsCommentServiceImpl implements DtsCommentService {

    @Autowired
    DtsCommentMapper commentMapper;

    /**
     *
     * @param page  当前页面
     * @param limit 每页条数
     * @param sort 排序字段
     * @param order 排序方式
     * @param goodsId 商品id
     * @param userId 用户id
     * @param brandIds 品牌id
     * @return 评论分页数据
     */
    @Override
    public IPage<DtsComment> queryPage(Integer page, Integer limit, String sort, String order, Integer goodsId, Integer userId, List<Integer> brandIds) {

        IPage<DtsComment> ipage = new Page<>(page, limit);

        QueryWrapper<DtsComment> qw = new QueryWrapper<>();
        if(goodsId != null){
            qw.eq("c.value_id", goodsId );
        }
        if(userId != null){
            qw.eq("c.user_id", userId );
        }

        //品牌
        if(brandIds != null &&  brandIds.size() > 0) {
            qw.in("g.brand_id", brandIds);
        }

        ipage = commentMapper.selectCommentPage(ipage, qw);
        return ipage;
    }

    @Override
    public void delete(DtsComment comment) {
        comment.setDeleted(true);
        commentMapper.updateById(comment);
    }


}
